<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Clean Blog - Start Bootstrap Theme</title>
<!-- Bootstrap Core CSS -->
	<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Additional fonts for this theme -->
	<link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
	<link href="/css/style.css?v=4.1.0" rel="stylesheet">
<style>
.navbar-toggler {
	z-index: 1;
}

@media ( max-width : 576px) {
	nav>.container {
		width: 100%;
	}
}
.top-offset{
	margin-top:30px;
}
</style>
</head>
<body>
	<!-- Main Content -->
	<div class="container top-offset">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="regForm">
							<input type="hidden" name="type" id="type" value="2">
								<div class="form-group">
									<label class="col-sm-3 control-label">姓名：</label>
									<div class="col-sm-8">
										<input id="name" name="name" class="form-control" type="text">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">登录名：</label>
									<div class="col-sm-8">
										<input id="userName" name="userName" class="form-control"
											   type="text">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label">学号：</label>
									<div class="col-sm-8">
										<input id="userId" name="userId" class="form-control"
											   type="text">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label">密码：</label>
									<div class="col-sm-8">
										<input id="password" name="password" class="form-control"
											   type="password">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">确认密码：</label>
									<div class="col-sm-8">
										<input id="confirm_password" name="confirm_password"
											   class="form-control" type="password">
									</div>
								</div>

								<div class="form-group">
									<label class="col-sm-3 control-label">性别:</label>
									<div class="col-sm-8">
										<label class="radio-inline"> <input type="radio"
																			name="sex" value="1" checked/> 男
										</label> <label class="radio-inline"> <input type="radio"
																					 name="sex" value="0" /> 女
									</label>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">家长联系号码：</label>
									<div class="col-sm-8">
										<input id="mobile" name="mobile" class="form-control"
											   type="text">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">所在班级：</label>
									<div class="col-sm-8">
										<select data-placeholder="--选择班级--" name="unit" id="unit"
												class="form-control chosen-select" tabindex="2">
											<option value="">-- 选择班级 --</option>
											<option value="1">一年级</option>
											<option text="二年级" value="2">二年级</option>
											<option text="三年级" value="3">三年级</option>
											<option text="四年级" value="4">四年级</option>
											<option text="五年级" value="5">五年级</option>
											<option text="六年级" value="6">六年级</option>
										</select>
<!--										<input id="unit" name="unit" class="form-control"-->
<!--											   type="text">-->
									</div>
								</div>



							<div class="form-group">
								<div class="col-sm-5 col-sm-offset-5">
									<button type="submit" class="btn btn-primary">提交</button>
									<button  style="margin-left:20px" class="btn btn-danger" onclick="closeReg()">关闭</button>
								</div>
							</div>

						</form>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- 全局js -->
	<script src="/js/jquery.min.js?v=2.1.4"></script>
	<script src="/js/bootstrap.min.js?v=3.3.6"></script>

	<!-- 自定义js -->
	<script src="/js/content.js?v=1.0.0"></script>

	<!-- jQuery Validation plugin javascript-->
	<script src="/js/plugins/validate/jquery.validate.min.js"></script>
	<script src="/js/plugins/validate/messages_zh.min.js"></script>
	<script src="/js/plugins/layer/layer.min.js"></script>


	<script type="text/javascript">
		$().ready(function() {
			validateRule();
		});


		$.validator.setDefaults({
			submitHandler : function() {
				save();
			}
		});

		function save() {
			$.ajax({
				cache : true,
				type : "POST",
				url : "/registry/save",
				data : $('#regForm').serialize(),// 你的formid
				async : false,
				error : function(request) {
					parent.layer.alert("Connection error");
				},
				success : function(data) {
					if (data.code == 0) {
						parent.layer.msg("注册成功");
						var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
						parent.layer.close(index);

					} else {
						parent.layer.alert(data.msg)
					}

				}
			});

		}

		function closeReg(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}

		function validateRule() {
			var icon = "<i class='fa fa-times-circle'></i> ";
			$("#regForm").validate({
				rules : {
					name : {
						required : true
					},
					userName : {
						required : true,
						minlength : 2,
						remote : {
							url : "/registry/exsit", // 后台处理程序
							type : "post", // 数据发送方式
							dataType : "json", // 接受数据格式
							data : { // 要传递的数据
								username : function() {
									return $("#userName").val();
								}
							}
						}
					},
					password : {
						required : true,
						minlength : 6
					},
					confirm_password : {
						required : true,
						minlength : 6,
						equalTo : "#password"
					},
					mobile : {
						required : true
					},
					userId : {
						required : true
					}

				},
				messages : {

					name : {
						required : icon + "请输入姓名"
					},
					userName : {
						required : icon + "请输入您的用户名",
						minlength : icon + "用户名必须两个字符以上",
						remote : icon + "用户名已经存在"
					},
					password : {
						required : icon + "请输入您的密码",
						minlength : icon + "密码必须6个字符以上"
					},
					confirm_password : {
						required : icon + "请再次输入密码",
						minlength : icon + "密码必须6个字符以上",
						equalTo : icon + "两次输入的密码不一致"
					},
					mobile : icon + "请输入联系方式",
					userId : icon + "请输入学号",
				}
			})
		}
	</script>

</body>

</html>
